<?php

use Illuminate\Support\Facades\Route;

use App\Http\Controllers\CommonController;
use App\Http\Controllers\OneController;
use App\Http\Controllers\BlogController;
use Illuminate\Support\Facades\Broadcast;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});


//统一路由
Route::Group([], function () {
    Route::get('/dispatch', 'CommonController@jyDispatch');
});

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth'])->name('dashboard');

Route::get('/profile', function () {
    return request()->user();
})->middleware(['auth'])->name('profile');

require __DIR__.'/auth.php';

/**自定义代码 */
// visit http://host/aaa
Route::get('aaa', function () {
    return "hello world!";
});

//visit http://host/post
Route::post('post', function () {
    return "post";
});

//visit http://host/dup any http method
// 同名路由 会被覆盖
Route::any('dup', function () {
    return "index";
});

Route::any('dup', function () {
    return "xxxxx";
});

/** 跳转*/
Route::redirect('index', 'task'); // /index 跳转 /task  302

//visit http://host/list  get post
Route::match(['get', 'post'],'list', function () {
    return "get or post list!";
});

//pass args
/*Route::get('/{action}', function ($id) {
    return "hello world! {$id}";
});*/

/** 使用控制器 */
Route::get('com', [CommonController::class, 'index']);

//Route::get('com/read/{param1}', [CommonController::class, 'read']);

//控制器内约束参数
/*Route::get('com/read/{param1s}', [CommonController::class, 'read'])
    //->where('id', '[0-9]+');
    ->where(['id' => '[0-9]+', 'name' => '[a-z]+']);*/

//解除全局限制RouteServiceProvider
//Route::get('com/read/{param1}', [CommonController::class, 'read'])
//    ->where('id', '.*');

/** 使用视图
 * 1.直接在view路由中指定视图地址
 * 2.在路由,函数中指定view
 * 3.在控制器中指定view
 */
Route::view('taskview','task', ['id' => 10]);

Route::get('task2', function (){
    return view('task',['id' => 10]);
});


Route::get('com/fun', [CommonController::class, 'fun']);



Route::get('com/show', [CommonController::class, 'show']);
//Route::redirect('show', 'com/show', 301);
Route::permanentRedirect('show', 'com/show');  //=301跳转


/**路由命名和分组*/
//路由命名
Route::get('com/url', [CommonController::class, 'url'])->name('task.url');
Route::get('com/url/{id2}', [CommonController::class, 'url'])->name('task.url2');
Route::get('taskindex',[CommonController::class, 'index'])->name('task.index');
Route::get('com/redirect',[CommonController::class, 'redirect']); //通过路由名跳转

//路由前缀
Route::prefix('api')->get('task',[CommonController::class, 'index']);

//只是个分组 分组啥也不做
Route::group([], function(){
    Route::get('demo', function (){
        return 'demo';
    });
    Route::get('demo/hi', function(){
        return 'hi';
    });
});

//指定前缀再分组
Route::prefix('api')->group(function(){
    Route::get('beauty', function (){
        return 'beauty';
    });
    Route::get('beauty/go', function(){
        return 'go';
    });
});


//分组可以指定前缀，中间件、子域名
Route::group(['prefix' => 'api'], function(){
    Route::get('hall', function (){
        return 'demo';
    });
    Route::get('hall/hi', function(){
        return 'hi';
    });
});

Route::name('mini.')->group(function(){
    Route::get('alias', function (){   //curl localhost/comm 返回 route('mini.index')的url地址
        return route('mini.index');
    });
    Route::get('core', [CommonController::class, 'index'])->name('index'); // curl localhost/core
});

/**单行为控制器*/
Route::get('one', OneController::class);


/**获取当前的路由信息*/
Route::get('com/route', [CommonController::class, 'route']);
#sRoute::get('com/route', [CommonController::class, 'route'])->name('task.route1');


/** 格式化响应 */
Route::get('com/out', [CommonController::class, 'out']);

/**资源控制器
 * 专门处理crud的控制器，包括html表单
 * 专门处理crud的api控制器
 */

//资源控制器路由
Route::resource('blogs', BlogController::class);
//Route::resource('blogs', BlogController::class)->only(['index', 'show']);
//Route::resource('blogs', BlogController::class)->except(['store', 'edit']);
//批量资源路由
//Route::resources(['blogs' => BlogController::class]);

//api资源路由
//Route::apiResource('blogs', BlogController::class);

//资源嵌套、浅嵌套
use App\Http\Controllers\CommentController;
//Route::resource('blogs.comments', CommentController::class);
Route::resource('blogs.comments', CommentController::class)->shallow();

Route::match(['get','post','put','delete'],'blog/post', [BlogController::class, 'store']);

use App\Http\Controllers\DataController;
use App\Http\Controllers\LampUserController;
Route::any('data', [DataController::class, 'index']);
Route::any('data/model', [DataController::class, 'tablemodel']);

Route::any('com/myrequest', [CommonController::class, 'myrequest']);
Route::get('com/tmp/{id}', [CommonController::class, 'param']);  #只要使用{id} 访问就报404
Route::get('com/params1/{cate1}/{cate2}', [CommonController::class, 'params1']);
Route::get('com/params2/{cate1}/{cate2}', [CommonController::class, 'params2']);
Route::get('com/params3/{cate1}/{cate2}', [CommonController::class, 'params3']);
Route::get('com/url2/{id2}', [CommonController::class, 'url'])->name('task.url2');

# 视图文件
Route::get('view/view', 'ViewController@view');
Route::any('view/indexview', 'ViewController@indexview');
Route::any('view/mulitView', 'ViewController@mulitView');



Route::any('com/form', [CommonController::class, 'form']);
Route::any('com/receive', [CommonController::class, 'receive']);

Route::any('com/receive', [CommonController::class, 'receive']);
Route::any('com/check', [CommonController::class, 'checked']);

Route::any('com/app', [CommonController::class, 'app']); //larval 还不支持属性注解
Route::any('com/container', [CommonController::class, 'container']); //调用容器的对象

Route::any('data/page', [DataController::class, 'page']);
Route::any('com/envFile', 'CommonController@envFile');

Route::any('container/app', 'ContainerController@app'); //larval 还不支持属性注解
Route::any('container/apppro', 'ContainerController@appPro'); //调用容器的对象
Route::any('container/UseContainer', 'ContainerController@UseContainer');
Route::any('container/container', 'ContainerController@container');

/** 默认回退路由，当路由不存在是的默认路由，必须放在最后*/
/*Route::fallback(function(){
    return  redirect('/');
});*/
